package com.woniuxy.learnmap.service.impl;

import com.woniuxy.commons.entity.Certificate;
import com.woniuxy.commons.exception.EtmsServiceException;
import com.woniuxy.commons.exception.learnmap.CertificateNameAlReadyExistException;
import com.woniuxy.learnmap.mapper.CertificateMapper;
import com.woniuxy.learnmap.service.CertificateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: 王敞
 * @E-mail： 365799712@qq.com
 * @Date: 2020/07/27/16:01
 * @Description:
 */
@Service
public class CertificateServiceImpl implements CertificateService {
    @Autowired
    private CertificateMapper certificateMapper;
    /*
    *
     * @Description: 新增一个证书
     * @Param: [certificate]
     * @return: void
     * @Author: 王敞
     * @Date: 16:02 2020/7/27
     **/
    @Override
    public void addCertificate(Certificate certificate) {
        //先判断该证书名字是否已经被使用
        Certificate certificate1=certificateMapper.findCertificateByName(certificate.getName());
        if(certificate1 != null){
            throw new CertificateNameAlReadyExistException("该证书名字已存在");
        }
        try{
            certificateMapper.addCertificate(certificate);
        }catch (Exception e){
            e.printStackTrace();
            throw new EtmsServiceException("系统维护中");
        }
    }

    @Override
    public List<Certificate> findAllCertificates() {
        return certificateMapper.findAllCertificates();
    }
}
